<?php
require 'Admin/Controller/Controller.php ';
require 'Admin/Model/user/UserModel.php';

class UserController extends Controller{
    
	function __Construct(){
		parent::__Construct();
		$this->mod = 'users';
		$this->model = new UserModel();
	}

	//显示用户列表(查)
	function index(){

		$data = $this->model->getList();
		$this->assign('users',$data);
		$this->display();
		//return $data;

	}

	//修改用户信息(改)
	function mod(){
	    $id = $_GET['id'];
        $result = $this->model->getByID($id);
        $this->assign("user",$result);
        $this->display();
    }
    function update(){
        $data = $_POST;
        $result = $this->model->update($data);
        if($result){
            echo '更新成功 <a href="admin.php?c=user&m=index">如果没有跳转，请点这里跳转</a>';
            header("refresh:5;url='admin.php?c=user&m=index'");
        }
        else{
            echo "更新失败！<br/>";
            echo "<a href='admin.php?c=user&m=usermod&id=".$data['id']."'>返回</a>";
        }
    }

    //添加用户(增)
    function form(){
        $this->display();
    }
    function add(){
        $data = $_POST;
        $result = $this->model->add($data);
        if($result){
            echo '添加成功 <a href="admin.php?c=user&m=index">如果没有跳转，请点这里跳转</a>';
            header("refresh:5;url='admin.php?c=user&m=index'");
        }
        else{
            echo "添加失败！<br/>";
            echo "<a href='admin.php?c=user&m=form'>返回</a>";
        }
    }

    //删除用户(删)
    function del(){
        $id = $_GET['id'];
        $result = $this->model->del($id);
        if($result){
            echo '删除成功 <a href="admin.php?c=user&m=index">如果没有跳转，请点这里跳转</a>';
            header("refresh:5;url='admin.php?c=user&m=index'");
        }
        else{
            echo "删除失败！<br/>";
            echo "<a href='admin.php?c=user&m=index'>返回</a>";
        }
    }
}
?>